var express = require('express');
var router = express.Router();
var sqlite3 = require('sqlite3').verbose();
var path = require('path');

/* GET users listing. */
router.get('/', function(req, res, next) {
  var db=new sqlite3.Database(path.join(__dirname, "../db/userInfo.db3"));
  const username = req.query.username;
  const captcha= req.query.captcha;
  const pwd = req.query.password;
  try{
    db.serialize(function() {
        //sqlStr = "CREATE TABLE IF NOT EXISTS TBL_meta (ID varchar2(255), label varchar2(255))"
        sqlStr = "SELECT * from userInfo where userName='"+username+"'";
        db.all(sqlStr, function(err, rows) {
            if(rows[0]==undefined)
                res.send('0');
            else if(pwd != rows[0].pwd){
              res.send('3'); //密码错误
            }
            else if (captcha != req.session.captcha) {
                res.send('1'); //验证码错误
            } 
            else{
                res.send('2'); //验证成功
            // 验证通过，删除保存的验证码
                delete req.session.captcha;
            }
        });

    });
  }catch(ex){
    console.log(ex);
  }
});

module.exports = router;
// 后端断点 9229调试端口